{extend name="common/base"/}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-4">
	<h3 class="pb-3">编辑订单表</h3>
	<table class="layui-table layui-table-form">
		<tr><td class="layui-td-gray-2">县区</td>
			<td>
				
				<select name="region"  lay-reqText="请选择县区" lay-search="">
					
					{volist name=":get_region()" id="v"}
					<option value="{$v.id}" {eq name="$detail.region" value="$v.id" }selected="" {/eq}>{$v.nianji} </option>
					{/volist}
				</select>
			</td>
			<td class="layui-td-gray-2">采购商</td>
			<td>
				<select name="purchaser"  lay-reqText="请选择采购商" lay-search="">
					
					{volist name=":get_purchaser()" id="v"}
					<option value="{$v.id}" {eq name="$detail.purchaser" value="$v.id" }selected="" {/eq}>{$v.name} </option>
					{/volist}
				</select>
			</td>
			<td class="layui-td-gray-2">配送日期</td>
			<td><input type="text" name="delivery_time"  value="{if $detail.delivery_time > 0}{$detail.delivery_time|date='Y-m-d'}{/if}"  id="laydate_delivery_time" autocomplete="off" placeholder="请输入配送日期" class="layui-input"></td>
			<!-- <td class="layui-td-gray-2">商品名称<font>*</font></td>
			<td><input type="text" name="name"  lay-verify="required" lay-reqText="请完善商品名称" value="{$detail.name}" autocomplete="off" placeholder="请输入商品名称" class="layui-input"></td>
			
			<td class="layui-td-gray-2">规格</td>
			<td><input type="text" name="specification"  value="{$detail.specification}" autocomplete="off" placeholder="请输入规格" class="layui-input"></td> -->
		</tr>
				
				<tr><td class="layui-td-gray-2">订单号</td>
			<td><input type="text" name="order_no"  value="{$detail.order_no}" autocomplete="off" placeholder="请输入订单号" class="layui-input"></td>

				<td class="layui-td-gray-2">备注</td>
			<td><input type="text" name="remark"  value="{$detail.remark}" autocomplete="off" placeholder="请输入备注" class="layui-input"></td>
			<td class="layui-td-gray-2">状态</td>
			<td><input type="text" name="status"  value="{$detail.status}" autocomplete="off" placeholder="请输入状态" class="layui-input"></td><td colspan='4'></td>
		</tr>
		<tr>
			<td class="layui-td-gray-2">出库数</td>
			<td><input type="text" name="out_storage"  value="{$detail.out_storage}" autocomplete="off" placeholder="请输入出库数" class="layui-input chukushu"></td><td class="layui-td-gray-2">入库数</td>
			<td><input type="text" name="in_storage"  value="{$detail.in_storage}" autocomplete="off" placeholder="请输入入库数" class="layui-input rukushu"></td>
			<!-- <td class="layui-td-gray-2">损耗</td><td class="sunhao"></td> -->
			<input type="hidden" class="fenjianliang">
		</tr>
		<tr>
			
		</tr>
		<tr>
			<td></td>
		</tr>
				<tr><td class="layui-td-gray-2">分拣员1</td>
			<td><!-- <input type="text" name="sorting_admin"  value="{$detail.sorting_admin}" autocomplete="off" placeholder="请输入分拣员" class="layui-input"> -->
				<select name="sorting_admin"  lay-reqText="请选择分拣员" lay-search="">
					<option value="0" >--请选择分拣员-- </option>
					{volist name=":get_fenjian()" id="v"}
					<option value="{$v.id}" {eq name="$detail.sorting_admin" value="$v.id" }selected="" {/eq}>{$v.name} </option>
					{/volist}
				</select>
			</td>
			<td class="layui-td-gray-2">分拣员2</td>
			<td><!-- <input type="text" name="sorting_admin"  value="{$detail.sorting_admin}" autocomplete="off" placeholder="请输入分拣员" class="layui-input"> -->
				<select name="sorting_admin2"  lay-reqText="请选择分拣员" lay-search="">
					<option value="0" >--请选择分拣员-- </option>
					{volist name=":get_fenjian()" id="v"}
					<option value="{$v.id}" {eq name="$detail.sorting_admin2" value="$v.id" }selected="" {/eq}>{$v.name} </option>
					{/volist}
				</select>
			</td>
			<td class="layui-td-gray-2">配送人</td>
			<td><input type="text" name="delivery_admin"  value="{$detail.delivery_admin}" autocomplete="off" placeholder="请输入配送人" class="layui-input"></td>

		</tr>
				<tr><td class="layui-td-gray-2">温馨提示</td>
			<td colspan="5"><input type="text" name="tip"  value="{$detail.tip}" autocomplete="off" placeholder="请输入温馨提示" class="layui-input"></td>

			
		</tr>
				<tr>
		</tr>
	</table>
	<div class="table_big2">
		
	</div>
	<div class="py-3">
		<input type="hidden" id="detail_list" value="{$detail_list}"/>
		<input type="hidden" name="id" value="{$detail.id}"/>
		<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
		<button type="reset" class="layui-btn layui-btn-primary">重置</button>
	</div>
</form>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	var moduleInit = ['tool'];

	function gouguInit() {
		var form = layui.form, tool = layui.tool;
		
		layui.laydate.render({
			elem: '#laydate_delivery_time' //指定元素
			//,type:'date'
		});
		//商品列表
		let detail_list = $("#detail_list").val();
		let detail_json = JSON.parse(detail_list);
		let s=0;
		let new_html='';
		new_html='<div class="layui-col-md12">'
+'		<div class="layui-card">'
+'			<div class="p-3">'
+'				<table class="layui-table">'
+'					<thead>'
+'						<tr>'						
+'							<th style="text-align:center">编号</th>'
+'							<th style="text-align:center">商品名</th>'
+'							<th style="text-align:center">规格</th>'
/*+'							<th style="text-align:center">单价</th>'*/
+'							<th style="text-align:center">生产日期</th>'
/*+'							<th style="text-align:center">下单量（斤）</th>'*/
+'							<th style="text-align:center">分拣量（斤）</th>'
/*+'							<th style="text-align:center">分拣合计（元）</th>'*/
+'							<th style="text-align:center">客户备注</th>'

+'						</tr>'
+'					</thead>'
+'					<tbody class="layui-table-body">'
+'						';
		for(let i=0;i<detail_json.length;i++){
			s=i+1;
			if(detail_json[i].price===null || detail_json[i].price==''){detail_json[i].price=''}
			if(detail_json[i].produced_time==null || detail_json[i].produced_time==''){detail_json[i].produced_time=''}
			new_html +='<tr>'
+'							<td align="center">'+s+'</td>'					
+'							<td align="center">'+detail_json[i].name+'</td>'
+'							<td align="center">'+detail_json[i].name+'</td>'
/*+'							<td align="center">'+detail_json[i].price+'</td>'*/
+'							<td align="center">'+detail_json[i].produced_time+'</td>'
+'							<td align="center">'+detail_json[i].sorting+'</td>'
/*+'							<td align="center">'+detail_json[i].sorting+'</td>'*/
+'							<td align="center">'+detail_json[i].remark+'</td>'
+'						</tr>';
		}
new_html+='					</tbody>'
+'				</table>'
+'			</div>'
+'		</div>'
+'	</div>'
$(".table_big2").append(new_html);

		//损耗
		/*$('.chukushu, .rukushu, .fenjianliang').on('input', function() {
        // 获取输入值并转为数字（空值处理为0）
	        const outVal = parseFloat($('.chukushu').val()) || 0;
	        const inVal = parseFloat($('.rukushu').val()) || 0;
	        const sortVal = parseFloat($('.fenjianliang').val()) || 0;

	        // 当出库和入库都有值时触发计算
	        if ($('.chukushu').val() && $('.rukushu').val()) {
	            // 计算损耗 = 出库数 - 分拣量 - 入库数
	            const wastage = outVal - sortVal - inVal;
	            
	            // 更新损耗输入框（假设有对应的DOM元素）
	            //$('input[name="wastage"]').val(wastage.toFixed(2)); // 保留两位小数
	            $('.sunhao').html(wastage.toFixed(2)); // 保留两位小数
	            form.render(); // 重要：刷新Layui样式
	        }
	    });
	    const outVal = parseFloat($('.chukushu').val()) || 0;
	        const inVal = parseFloat($('.rukushu').val()) || 0;
	        const sortVal = parseFloat($('.fenjianliang').val()) || 0;

	        // 当出库和入库都有值时触发计算
	        if ($('.chukushu').val() && $('.rukushu').val()) {
	            // 计算损耗 = 出库数 - 分拣量 - 入库数
	            const wastage = outVal - sortVal - inVal;
	            
	            // 更新损耗输入框（假设有对应的DOM元素）
	            //$('input[name="wastage"]').val(wastage.toFixed(2)); // 保留两位小数
	            $('.sunhao').html(wastage.toFixed(2)); // 保留两位小数
	            form.render(); // 重要：刷新Layui样式
	        }*/

		//监听提交
		form.on('submit(webform)', function (data) {
			
			let callback = function (e) {
				layer.msg(e.msg);
				if (e.code == 0) {
					tool.sideClose(1000);
				}
			}
			tool.post("/admin/order/edit", data.field, callback);
			return false;
		});
	}
</script>
{/block}
<!-- /脚本 -->